// vue.config.js
const webpack = require('webpack')
let path = require('path');
function resolve(dir) {
	return path.join(__dirname, dir)
}

let isTest = 3
module.exports = {
	chainWebpack: config => {
		config.plugin('provide').use(webpack.ProvidePlugin, [{
			'window.Quill': 'quill'
		}])
		config.resolve.alias.set('@', resolve('src')),
			config.resolve.alias.set('vue$', 'vue/dist/vue.js')
	},
	configureWebpack: config => {
		config.module.noParse = /^(vu|vue-router|vuex|vuex-router-sync|lodash|echarts|axios|element-ui)$/,
		config.optimization.splitChunks = {
			chunks: 'all', // 表示哪些代码需要优化，有三个可选值：initial(初始块)、async(按需加载块)、all(全部块)，默认为async
			maxInitialRequests: Infinity, // 按需加载时候最大的并行请求数，默认为5
			minSize: 30000, // 依赖包超过300000bit将被单独打包
			// 缓存组
			// priority: 缓存组打包的先后优先级
			// minChunks: 表示被引用次数，默认为1
			cacheGroups: {
				//公共模块
				commons: {
					name: 'chunk-commons',
					test: resolve('src'), // can customize your rules
					minSize: 100, //大小超过100个字节
					minChunks: 3, //  minimum common number
					priority: 5,
					reuseExistingChunk: true
				},
				vendors: {
					name: 'vendors',
					test: /[\\/]node_modules[\\/]/,
					chunks: 'initial',
					priority: 2,
					reuseExistingChunk: true,
					enforce: true
				},
				elementUI: {
					name: 'elementui',
					test: /[\\/]node_modules[\\/]element-ui[\\/]/,
					chunks: 'all',
					priority: 3,
					reuseExistingChunk: true,
					enforce: true
				},
				echarts: {
					name: 'chunk-echarts',
					test: /[\\/]node_modules[\\/]echarts[\\/]/,
					chunks: 'all',
					priority: 12,
					reuseExistingChunk: true,
					enforce: true
				}
			}
		}
	},
	publicPath: './',
	outputDir: isTest==1?'../家具大师-深哥-测试服务器-家具大师服务器/public/web/admin':isTest==2?'../家具大师-深哥-测试服务器/public/web/admin':'../家具大师-深哥-正式服务器/public/web/admin', // 打包的目录
	lintOnSave: false, // 在保存时校验格式
	productionSourceMap: false, // 生产环境是否生成 SourceMap
	devServer: {
		open: true, // 启动服务后是否打开浏览器
		host: '0.0.0.0',
		port: 8080, // 服务端口
		https: false,
		hotOnly: false,
		proxy: {
			'/restapi': {
				target: 'https://tst.shengejiaju.cn/',
				changeOrigin: true,
				pathRewrite: {
					'^/restapi': ''
				}
			}
		},
		before: app => { }
	}
}